﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Acaweb.Servicios.Utility;

namespace Acaweb.Servicios.Security
{
    public class User
    {
        private string _Name;
        private string _Username;
        private string _Email;
        private string _Token;
        private Ambitos _Rol;
        //private string _AlterUsername;

        //public string AlterUsername
        //{
        //    get { return _AlterUsername; }
        //    set { _AlterUsername = value; }
        //}

        public Ambitos Rol
        {
            get { return _Rol; }
            set { _Rol = value; }
        }

        public string Username
        {
            get { return _Username; }
            set { _Username = value; }
        }

        public string Name
        {
            get { return _Name; }
            set { _Name = value; }
        }

        public string Email
        {
            get { return _Email; }
            set { _Email = value; }
        }

        public int ToInt()
        {
            string Username = this.Username;
            int Codigo = 0;
            int.TryParse(Username, out Codigo);

            return Codigo;
        }

        public string getUserEmail()
        {
            return _Email.Substring(0, _Email.LastIndexOf("@"));
        }

        public void SetAlterUsername()
        {
            if (Username.Contains("   "))
                Username = Username.Substring(0, Username.IndexOf(" "));
        }

        public void UpdateRol()
        {
            SetAlterUsername();

            string[] Roles = new Acaweb.Services.Security.Providers.ADRoleProvider().GetRolesForUser(Username);

            if (Roles.Contains("GD_DOCENTE"))
                Rol = Ambitos.Docente;
            if (Roles.Contains("GWEB_ESTUDIANTE"))
                Rol = Ambitos.Estudiante;
            if (Roles.Contains("GWEB_EGRESADOS"))
                Rol = Ambitos.Egresado;
        }

        public string Token
        {
            get { return _Token; }
            set { _Token = value; }
        }

        //public string AlterToken
        //{
        //    get { return _Token; }
        //    set { _Token = value; }
        //}
    }
}